#include "Arduino.h"
#include <Keypad.h>
#include <rconkeypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
  {'2','1','3'},
  {'0','*','#'},
  {'8','7','9'},
  {'5','4','6'}
};

byte rowPins[ROWS] = {8, 10, 12, 13}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 9, 11}; //connect to the column pinouts of the keypad

char rconkeypad::getKey()
{
  Keypad k=Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
  char c=k.getKey();
  if(c=='*' || (c>='0' && c<='9') || c=='#')
    return c;
  else return 'a';
}  

long rconkeypad::scanKeypad()
{
  long num=0;
  Keypad k=Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
  char c=k.getKey();
  while(c!='#')
  {
    if(c!='*' && c>='0' && c<='9')
      {
        num=num*10+(c-'0');
        Serial.println(num);
      }
     else if(c=='*') {num=num/10;Serial.println(num);}
      c=k.getKey();
  }
  return num;
}

void rconkeypad::longTochar(long num,char *buffer)
{
  ltoa(num,buffer,10);
}

long rconkeypad::charTolong(char *buffer)
{
   long n;
   n=atol(buffer);
   return n;
}
